package com.essearch.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.sql.Connection;
import java.sql.DriverManager;

@Component
public class DBHelper {
    private static String url;
    @Value("${database.url}")
    public void setUrl(String url) {
        DBHelper.url = url;
    }

    private static String user;
    @Value("${database.username}")
    public void setUser(String user) {
        DBHelper.user = user;
    }

    private static String password;
    @Value("${database.password}")
    public void setPassword(String password) {
        DBHelper.password = password;
    }

    public static String name;
    @Value("${database.drivername}")
    public void setName(String name) {
        DBHelper.name = name;
    }

    private static Connection conn = null;

    public static Connection getConn(String dbName) {
        try {
            Class.forName(name);
            conn = DriverManager.getConnection(url, user, password);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return conn;
    }
}
